package org.arain.spring.captive.portal.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.arain.spring.captive.portal.utils.EhcacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import top.zhaoyuliu.summer.common.utils.AppUtils;
import top.zhaoyuliu.summer.core.controller.BaseController;
import top.zhaoyuliu.summer.core.result.ResultMap;

/**
 *
 * @author Arain
 * @date 2019年6月28日 上午11:31:03
 */
@Controller
public class IndexController extends BaseController {

	@Autowired
	private EhcacheUtil ehcacheUtil;

	@RequestMapping("portal")
	public String portal(HttpServletRequest request, HttpServletResponse response) throws IOException {
		return "portal";
	}

	@RequestMapping("login")
	@ResponseBody
	public ResultMap login(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		if ("admin".equals(username) && "admin".equals(password)) {
			String ipAddr = AppUtils.getIpAddr(request);
			System.out.println("认证IP "+ipAddr);
			ehcacheUtil.put("timeCache", ipAddr, ipAddr);
			return success();
		}
		return faild();
	}
}
